lib: Drop GFile variant mapping API for fd-relative
authorColin Walters <walters@verbum.org>
Tue, 31 May 2016 15:53:27 +0000 (11:53 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Wed, 1 Jun 2016 15:02:41 +0000 (15:02 +0000)
In addition to generic fd relative porting,
this is a necessary preparatory step for libglnx porting, because
when I tried to use `g_mapped_file_new` I hit an issue with
it using a different error domain from GIO.

Thankfully libglnx consistently uses the GIO error domain, and here
we're now using it for the `open()` call.

Closes: #317
Approved by: jlebon

src/libostree/ostree-repo-commit.c
src/libostree/ostree-repo.c
src/libotutil/ot-variant-utils.c
src/libotutil/ot-variant-utils.h
src/ostree/ot-builtin-show.c

index 8f5067c04198dfad829d0e15f331bb8b7401f86a..96403d61dd080489ed61aed9c26a870ce3734397 100644 (file)
@@ -2098,8 +2098,9 @@ ostree_repo_read_commit_detached_metadata (OstreeRepo      *self,
   g_autoptr(GVariant) ret_metadata = NULL;
   GError *temp_error = NULL;
   
-  if (!ot_util_variant_map (metadata_path, G_VARIANT_TYPE ("a{sv}"),
-                            TRUE, &ret_metadata, &temp_error))
+  if (!ot_util_variant_map_at (AT_FDCWD, gs_file_get_path_cached (metadata_path),
+                               G_VARIANT_TYPE ("a{sv}"),
+                               TRUE, &ret_metadata, &temp_error))
     {
       if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
         {
index 36c2ac4462288193d2a1e865ea9ea7095fdcf4d5..2332d2bb66db0caf07f78d00564977869c981ce7 100644 (file)
@@ -4627,8 +4627,9 @@ ostree_repo_add_gpg_signature_summary (OstreeRepo     *self,
   if (!summary_data)
     goto out;
 
-  if (!ot_util_variant_map (signature_path, G_VARIANT_TYPE (OSTREE_SUMMARY_SIG_GVARIANT_STRING),
-                            TRUE, &existing_signatures, &temp_error))
+  if (!ot_util_variant_map_at (AT_FDCWD, gs_file_get_path_cached (signature_path),
+                               G_VARIANT_TYPE (OSTREE_SUMMARY_SIG_GVARIANT_STRING),
+                               TRUE, &existing_signatures, &temp_error))
     {
       if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
         {
index b9fe94b94d54dd3ecc2e4a8ae8f9a51ef84822fd..26054459f8b277907436690c5b71ff76cb063c66 100644 (file)
@@ -117,46 +117,6 @@ ot_util_variant_take_ref (GVariant *variant)
   return g_variant_take_ref (variant);
 }
 
-/**
- * ot_util_variant_map:
- * @src: a #GFile
- * @type: Use this for variant
- * @trusted: See documentation of g_variant_new_from_data()
- * @out_variant: (out): Return location for new variant
- * @error:
- *
- * Memory-map @src, and store a new #GVariant referring to this memory
- * in @out_variant.  Note the returned @out_variant is not floating.
- */
-gboolean
-ot_util_variant_map (GFile              *src,
-                     const GVariantType *type,
-                     gboolean            trusted,
-                     GVariant          **out_variant,
-                     GError            **error)
-{
-  gboolean ret = FALSE;
-  g_autoptr(GVariant) ret_variant = NULL;
-  GMappedFile *mfile = NULL;
-
-  mfile = gs_file_map_noatime (src, NULL, error);
-  if (!mfile)
-    goto out;
-
-  ret_variant = g_variant_new_from_data (type,
-                                         g_mapped_file_get_contents (mfile),
-                                         g_mapped_file_get_length (mfile),
-                                         trusted,
-                                         (GDestroyNotify) g_mapped_file_unref,
-                                         mfile);
-  g_variant_ref_sink (ret_variant);
-  
-  ret = TRUE;
-  ot_transfer_out_value(out_variant, &ret_variant);
- out:
-  return ret;
-}
-
 gboolean
 ot_util_variant_map_at (int dfd,
                         const char *path,
index 1a7abe0e3a40c3b66b013a0d224fb15db60c039e..f185b4fdb9e9dfdfa45a5de1685b82cb7f886629 100644 (file)
@@ -42,12 +42,6 @@ gboolean ot_util_variant_save (GFile *dest,
                                GCancellable *cancellable,
                                GError  **error);
 
-gboolean ot_util_variant_map (GFile *src,
-                              const GVariantType *type,
-                              gboolean trusted,
-                              GVariant **out_variant,
-                              GError  **error);
-
 gboolean ot_util_variant_map_at (int dfd,
                                  const char *path,
                                  const GVariantType *type,
index a1b4db5ffa583b4b8b5b4c6ee8cef02b9d64e0dd..ef541c2a7ac957d4da92e5f58c0aa723c55b86e7 100644 (file)
@@ -51,12 +51,9 @@ do_print_variant_generic (const GVariantType *type,
                           GError **error)
 {
   gboolean ret = FALSE;
-  g_autoptr(GFile) f = NULL;
   g_autoptr(GVariant) variant = NULL;
 
-  f = g_file_new_for_path (filename);
-
-  if (!ot_util_variant_map (f, type, TRUE, &variant, error))
+  if (!ot_util_variant_map_at (AT_FDCWD, filename, type, TRUE, &variant, error))
     goto out;
 
   ot_dump_variant (variant);